//
//  BDGroupChooseTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/6/9.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDGroupChooseTableViewCell.h"
#import <JMessage/JMessage.h>

@interface BDGroupChooseTableViewCell ()

@property (nonatomic, strong) UIImageView *chooseImageView;
@property (nonatomic, assign) BDGroupChooseState chooseState;

@end

@implementation BDGroupChooseTableViewCell

- (void)configeWithModel:(id)model chooseState:(BDGroupChooseState)chooseState{
    JMSGUser *friend = model;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:friend.avatar] placeholderImage:[UIImage imageNamed:@"avatar"]];
    self.textLabel.text = friend.nickname;
    self.chooseState = chooseState;
}

- (void)setChooseState:(BDGroupChooseState)chooseState{
    _chooseState = chooseState;
    if (_chooseState == BDGroupChooseStateNormal) {
        self.chooseImageView.image = [UIImage imageNamed:@"group_weixuanzhong"];
    }else if (_chooseState == BDGroupChooseStateAlready) {
        self.chooseImageView.image = [UIImage imageNamed:@"group_yicunzai"];
    }else if (_chooseState == BDGroupChooseStateNewAdd) {
        self.chooseImageView.image = [UIImage imageNamed:@"group_xuanzhong"];
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.chooseImageView.size = CGSizeMake(23, 23);
    self.chooseImageView.left = 10;
    self.chooseImageView.centerY = self.height / 2.0;
    
    self.imageView.size = CGSizeMake(45, 45);
    self.imageView.left = self.chooseImageView.right + 10;
    self.imageView.centerY = self.height / 2.0;
    self.imageView.layer.masksToBounds = YES;
    self.imageView.layer.cornerRadius = self.imageView.width / 2.0;
    
    self.textLabel.font = [UIFont systemFontOfSize:13];
    [self.textLabel sizeToFit];
    self.textLabel.left = self.imageView.right + 10;
    self.textLabel.centerY = self.height / 2.0;
    
}

- (UIImageView *)chooseImageView{
    if (!_chooseImageView) {
        self.chooseImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_chooseImageView];
    }
    return _chooseImageView;
}

@end
